/**
 * 
 */
package weather.language.forecast;

import java.util.*;

import weather.dictionary.ConditionAnswersDictionary;

public class Condition
{
	public Condition(String description)
	{
		description = description.trim();
		//description = description.toLowerCase();
		this.description = description;
	}
	
	public String getDescription()
	{
		return description;
	}
	
	public Set<ConditionsGroup> getGroups()
	{
		return groups;
	}
	
	public void addToGroup(ConditionsGroup group)
	{
		simpleAddToGroup(group);
		group.simpleAddCondition(this);
	}
	
	public boolean belongsToGroup(ConditionsGroup group)
	{
		return groups.contains(group);
	}
	
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		
		Condition other = (Condition) obj;
		
		if (description == null)
		{
			if (other.description != null)
				return false;
		} 
		else if (!description.equals(other.description))
			return false;
		
		return true;
	}
	public String toString()
	{
		return ConditionAnswersDictionary.instance().getValue(description);
	}
	protected void simpleAddToGroup(ConditionsGroup group)
	{
		groups.add(group);
	}

	private String description;
	private Set<ConditionsGroup> groups = new HashSet<ConditionsGroup>();
}
